<#include "/admin/layout/layout_header.html"/>
<@head>
<link rel="stylesheet" href="${site_url}admin/css/custom/custom.min.css" type="text/css">
<link href="${site_url}admin/js/plugins/sweetalert/sweetalert.css" type="text/css"
      rel="stylesheet" media="screen,projection">
<link rel="stylesheet" href="${site_url}admin/js/plugins/animate-css/animate.css" type="text/css">
</@head>
<!-- //////////////////////////////////////////////////////////////////////////// -->
<!-- START CONTENT -->
<section id="content">

    <!--breadcrumbs start-->
    <div id="breadcrumbs-wrapper">
        <!-- Search for small screen -->
        <div class="header-search-wrapper grey hide-on-large-only">
            <i class="mdi-action-search active"></i>
            <input type="text" name="Search" class="header-search-input z-depth-2" placeholder="Explore Materialize">
        </div>
        <div class="container">
            <div class="row">
                <div class="col s12 m12 l12">
                    <h5 class="breadcrumbs-title">内容管理</h5>
                    <ol class="breadcrumbs">
                        <li><a href="${site_url}admin/dashboard">控制面板</a></li>
                        <li><a href="${site_url}admin/menu">内容管理</a></li>
                    </ol>
                </div>
            </div>
        </div>
    </div>
    <!--breadcrumbs end-->

    <!--start container-->
    <div class="container">
        <div class="section">
            <div class="caption">
                <div class="s12 m6 l4">
                    <a class="btn waves-effect teal waves-light" href="/admin/node/create">新建</a>
                </div>
            </div>
            <div class="divider"></div>
            <div class="row">
                <div class="col s12 m8 l12" style="min-height: 400px;">
                    <table class="striped">
                        <thead>
                        <tr>
                            <th data-field="id">Id</th>
                            <th data-field="name">标题</th>
                            <th data-field="author">作者</th>
                            <th data-field="email">标签</th>
                            <th data-field="role">创建时间</th>
                            <th data-field="createDate">最后更新时间</th>
                            <th data-field="operate">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list nodeList.getList() as node>
                            <tr id="${node.id}">
                                <td>${node.id}</td>
                                <td>${node.title}</td>
                                <td>${node.user.name}</td>
                                <td>${node.tags}</td>
                                <td>${node.createDate}</td>
                                <td>${node.updateDate}</td>
                                <td>
                                    <span class="edit"><a href="${site_url}admin/node/edit/${node.id}" title="编辑"><i
                                            class="mdi-image-edit"></i></a></span>
                                <span class="delete">
                                    <a href="#" title="删除" onclick="deletenode(${node.id})"><i
                                            class="mdi-action-delete"></i></a></span>
                                </td>
                            </tr>
                        </#list>
                        </tbody>
                    </table>
                </div>
                <div class="right-align">
                    <ul class="pagination">
                        <#if nodeList.pageNumber==1>
                            <li class="disabled"><a href="#!"><i class="mdi-navigation-chevron-left"></i></a></li>
                            <#else>
                                <li class="waves-effect"><a href="?page=1"><i
                                        class="mdi-navigation-chevron-left"></i></a>
                                </li>
                        </#if>
                        <#list 1..nodeList.totalPage as i>
                            <li class="<#if nodeList.pageNumber==i>active<#else>waves-effect</#if>"><a
                                    href="?page=${i}">${i}</a>
                            </li>
                        </#list>
                        <#if nodeList.pageNumber==nodeList.totalPage>
                            <li class="disabled"><a href="#!"><i
                                    class="mdi-navigation-chevron-right"></i></a></li>
                            <#else>
                                <li class="waves-effect"><a href="?page=${nodeList.totalPage}"><i
                                        class="mdi-navigation-chevron-right"></i></a></li>
                        </#if>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <!--end container-->
</section>
<!-- END CONTENT -->

<#include "/admin/layout/layout_footer.html" />
<@script>
<script type="text/javascript" src="${site_url}admin/js/plugins/sweetalert/sweetalert.min.js"
        tppabs="utf8sweetalert.min.js"></script>
<script>
    function deletenode(id) {
        swal({
                    title: "是否删除?跟随Node的评论也会随之删除.",
                    type: "info",
                    showCancelButton: true,
                    cancelButtonText: "取消",
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "删除",
                    closeOnConfirm: false,
                    showLoaderOnConfirm: true,
                },
                function () {
                    var deleteUrl = "${site_url}admin/node/doDelete";
                    $.ajax({
                        type: 'post',
                        url: deleteUrl,
                        complete: function (XMLHttpRequest, status) {
                            if (status == 'timeout') { //超时,status还有success,error等值的情况
                                swal("请求超时");
                            }
                        },
                        timeout: 600000,
                        data: {id: id},
                        crossDomain: true,
                        dataType: 'json',
                        error: function (jqXHR, textStatus, errorThrown) {
                            if (textStatus == "error") {
                                swal("系统错误");
                            }
                        },
                        success: function (data) {
                            console.log(data);
                            if (data['result'] == "SUCCESS") {
                                swal.close();
                                Materialize.toast('删除成功', 4000);
                                $("tr#" + id).addClass("animated infinite rotateOutDownRight");
                                setTimeout(function () {
                                    $("tr#" + id).fadeOut();
                                }, 550);
                            } else {
                                swal.close();
                                Materialize.toast('删除失败', 4000)
                            }
                        }
                    });
                });
    }
</script>
</@script>